package com.campus.secondhand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.campus.secondhand.common.Result;
import com.campus.secondhand.entity.ProductImages;
import com.campus.secondhand.mapper.ProductImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductImageServiceImpl {

    @Autowired
    private ProductImageMapper productImageMapper;

    /**
     * 删除商品的所有图片
     * 
     * @param productId 商品ID
     * @return 操作结果
     */
    @Transactional
    public Result<Void> deleteProductImages(Long productId) {
        try {
            QueryWrapper<ProductImages> wrapper = new QueryWrapper<>();
            wrapper.eq("product_id", productId);
            productImageMapper.delete(wrapper);
            return Result.success(null, "商品图片删除成功");
        } catch (Exception e) {
            return Result.error("删除商品图片失败: " + e.getMessage());
        }
    }
}